/*
 * MPX_PCB.h
 *
 *	Created on: Sep 20, 2013
 *		Authors: Joseph DeLong, Justin Hamric, Alex Newcomer, Alex Bouvy
 */

#ifndef MPX_PCB_H_
#define MPX_PCB_H_

//Suggested definition of ProcessClass, as seen in R2 manual <<if(pcb->class == SYS) printf("Class: System");>>
#define SYS 0
#define APP 1

//process states
#define RUNNING 100
#define READY 1
#define WAITING 0
#define BLOCKED -1

//stack size
#define STACK_SIZE 1024

/*
 * Process Control Block structure
 * defined by Alex Newcomer, Joseph DeLong

 * processName:		character array, containing the lexical name of this PCB
 * processID:		integer representing a UNIQUE process ID number
 * processClass:	integer flag, representing whether this PCB contains a SYSTEM or APPLICATION process
 * priority:		integer, ranging from -128 to +127, representing the PRIORITY of this PCB's process
 * state:			integer flag, representing whether the process is READY, WAITING, or BLOCKED
 * isSuspended:		integer flag (either 0 or 1), representing whether this PCB's process is SUSPENDED
 * prev:			MPX_PCB pointer; should be assigned to point to the next-lowest PCB in this PCB's queue
 * next:			MPX_PCB pointer; should be assigned to point to the next-highest PCB in this PCB's queue
 * stack_base:		VOID pointer, points to the base of this PCB's stack
 * stack_top:		VOID pointer, points to the top of this PCB's stack
 * memorySize:		integer representing the size, in bytes, of this PCB's stack contents
 * load_address:	unsigned char string pointer representing the load address of this PCB in memory
 * exec_address:	unsigned char string pointer representing the executable address of this PCB in memory
 */
typedef struct MPX_PCB {
	char processName[9];
	int processID;
	int processClass;
	int priority;
	int pcb_state;
	int isSuspended;
	struct MPX_PCB *next;
	struct MPX_PCB *prev;
	unsigned char *stack_base;
	unsigned char *stack_top;
	int memorySize;
	unsigned char *load_address;
	unsigned char *exec_address;
} MPX_PCB;

/*
 * PCB Queue Structure
 * Defined by Justin Hamric
 *
 * count:	integer representing the number of MPX_PCBs in this queue
 * head:	MPX_PCB pointer, indicating the MPX_PCB structure at the head of this queue
 * tail:	MPX_PCB pointer, indicating the MPX_PCB structure at the tail of this queue
 */
typedef struct MPX_Q {
int count;
MPX_PCB* head;
MPX_PCB* tail;
} MPX_Q;

/*
 * PCB Context Structure
 * Copied from R3.pdf
 * general prupose registers:
 * 	AX - accumulator; used for logic, mult/div, in/out
 * 	BX - base address
 * 	CX - count register for loops
 * 	DX - data; like AX
 * 	SI - source index
 * 	DI - destination index
 * 	BP - base pointer; offset of SS; used for getting stack params
 * 	SP - stack pointer; points to top item of stack
 * segment registers:
 * 	CS - points at the memory segment containing the current program
 * 	DS - data segment; points at the segment where variables are defined
 * 	ES - extra segment register for use by programmer
 * 	SS - points at the segment contining the stack
 * 	IP - instruction pointer
 */
typedef struct context {
	unsigned int BP, DI, SI, DS, ES;
	unsigned int DX, CX, BX, AX;
	unsigned int IP, CS, FLAGS;
} context;

#endif /* MPX_PCB_H_ */
